<template>
  <t-row :gutter="[16, 16]">
    <t-col v-for="(item, index) in data" :key="item.title" :xs="6" :xl="3">
      <t-card
        :title="item.title"
        :bordered="false"
        :class="{
          'dashboard-item': true,
          'dashboard-item--main-color': index == 0,
        }"
      >
        <div class="dashboard-item-top">
          <span :style="{ fontSize: `${resizeTime * 28}px` }">
            <count-to :startVal="1" :endVal="item.number" :decimals="0" :duration="3000"></count-to>
          </span>
        </div>
        <div class="dashboard-item-left">
          <div
            v-if="index === 0"
            id="moneyContainer"
            class="dashboard-chart-container"
            :style="{
              width: `${resizeTime * 120}px`,
              height: '100px',
              marginTop: '-24px',
            }"
          ></div>
          <div
            v-else-if="index === 1"
            id="refundContainer"
            class="dashboard-chart-container"
            :style="{
              width: `${resizeTime * 120}px`,
              height: '56px',
              marginTop: '-24px',
            }"
          ></div>
          <span v-else-if="index === 2" :style="{ marginTop: `-24px` }">
            <!-- <usergroup-icon /> -->
          </span>
          <span v-else :style="{ marginTop: '-24px' }">
            <file-icon />
          </span>
        </div>
        <template #footer>
          <div class="dashboard-item-bottom">
            <div class="dashboard-item-block">
              {{ item.description }}
            </div>
            <t-icon name="chevron-right" />
          </div>
        </template>
      </t-card>
    </t-col>
  </t-row>
</template>

<script lang="ts">
export default {
  name: 'DashboardBase',
};
</script>

<script setup lang="ts">
import { FileIcon } from 'tdesign-icons-vue-next';
import {  ref } from 'vue';
import { CountTo } from 'vue3-count-to';
import {getStaticsData} from '@/api/statics'
import $eventBus from '@/utils/eventBus';

$eventBus.on('receiveMsgEvent',(data:string)=>{
  let d=JSON.parse(data)
  console.log('receiveMsgEvent '+data)
  if(d.Type==='dataStatics')
  {
    let staticsData=JSON.parse(d.Message)
    loadData(staticsData.Result)
  }
})
const resizeTime = ref(1);

 const data=ref([])
 data.value= [
  {
    title: '累计修图（张）',
    description: '智能图像的创建，修改',
    number: 28425,
    upTrend: '20.5%',
    leftType: 'echarts-line',
  },
  {
    title: '处理文档（个） ',
    description: '各类文档的结构化信息抽取和处理',
    number: 768,
    downTrend: '20.5%',
    leftType: 'echarts-bar',
  },
  {
    title: '处理视频（条）',
    description: '视频动漫化',
    number: 1126,
    upTrend: '20.5%',
    leftType: 'icon-usergroup',
  },
  {
    title: '处理音频（条）',
    description: '文字转语音',
    number: 527,
    downTrend: '20.5%',
    leftType: 'icon-file-paste',
  },
];
const fetchData=()=>{
  getStaticsData()
  .then(ret=>{
     loadData(ret)
  })
}

const loadData=(d:any)=>{
  data.value[0].number=d.pic
  data.value[1].number=d.doc
  data.value[2].number=d.video
  data.value[3].number=d.voice
}

fetchData()

</script>

<style lang="less" scoped>
.dashboard-item {
  padding: var(--td-comp-paddingTB-xl) var(--td-comp-paddingLR-xxl);

  :deep(.t-card__header) {
    padding: 0;
  }

  :deep(.t-card__footer) {
    padding: 0;
  }

  :deep(.t-card__title) {
    font: var(--td-font-body-medium);
    color: var(--td-text-color-secondary);
  }

  :deep(.t-card__body) {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex: 1;
    position: relative;
    padding: 0;
    margin-top: var(--td-comp-margin-s);
    margin-bottom: var(--td-comp-margin-xxl);
  }

  &:hover {
    cursor: pointer;
  }

  &-top {
    display: flex;
    flex-direction: row;
    align-items: flex-start;

    > span {
      display: inline-block;
      color: var(--td-text-color-primary);
      font-size: var(--td-font-size-headline-medium);
      line-height: var(--td-line-height-headline-medium);
    }
  }

  &-bottom {
    display: flex;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;

    > .t-icon {
      cursor: pointer;
      font-size: var(--td-comp-size-xxxs);
    }
  }

  &-block {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--td-text-color-placeholder);
  }

  &-trend {
    margin-left: var(--td-comp-margin-s);
  }

  &-left {
    position: absolute;
    top: 0;
    right: 0;

    > span {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: var(--td-comp-size-xxxl);
      height: var(--td-comp-size-xxxl);
      background: var(--td-brand-color-light);
      border-radius: 50%;

      .t-icon {
        font-size: 24px;
        color: var(--td-brand-color);
      }
    }
  }

  // 针对第一个卡片需要反色处理
  &--main-color {
    background: var(--td-brand-color);
    color: var(--td-text-color-primary);

    :deep(.t-card__title),
    .dashboard-item-top span,
    .dashboard-item-bottom {
      color: var(--td-text-color-anti);
    }

    .dashboard-item-block {
      color: var(--td-text-color-anti);
      opacity: 0.6;
    }

    .dashboard-item-bottom {
      color: var(--td-text-color-anti);
    }
  }
}
</style>
